package cn.iocoder.yudao.module.ao.dal.mysql.labschedule;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.ao.dal.dataobject.labschedule.LabScheduleDO;
import org.apache.ibatis.annotations.Mapper;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.module.ao.controller.admin.labschedule.vo.*;

/**
 * 机房实训室课 Mapper
 *
 * @author 禾安
 */
@Mapper
public interface LabScheduleMapper extends BaseMapperX<LabScheduleDO> {

    default PageResult<LabScheduleDO> selectPage(LabSchedulePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<LabScheduleDO>()
                .eqIfPresent(LabScheduleDO::getTerm, reqVO.getTerm())
                .likeIfPresent(LabScheduleDO::getLabName, reqVO.getLabName())
                .eqIfPresent(LabScheduleDO::getClassSection, reqVO.getClassSection())
                .eqIfPresent(LabScheduleDO::getMondayUsage, reqVO.getMondayUsage())
                .eqIfPresent(LabScheduleDO::getTuesdayUsage, reqVO.getTuesdayUsage())
                .eqIfPresent(LabScheduleDO::getWednesdayUsage, reqVO.getWednesdayUsage())
                .eqIfPresent(LabScheduleDO::getThursdayUsage, reqVO.getThursdayUsage())
                .eqIfPresent(LabScheduleDO::getFridayUsage, reqVO.getFridayUsage())
                .orderByDesc(LabScheduleDO::getId));
    }

    default LabScheduleDO selectByTermAndLabNameAndClassSection(String term, String labName, String classSection) {
        // 如果任何一个关键字段为空，直接返回null（表示不存在重复）
        if (StrUtil.isEmpty(term) || StrUtil.isEmpty(labName) || StrUtil.isEmpty(classSection)) {
            return null;
        }

        return selectOne(new LambdaQueryWrapperX<LabScheduleDO>()
                .eq(LabScheduleDO::getTerm, term)
                .eq(LabScheduleDO::getLabName, labName)
                .eq(LabScheduleDO::getClassSection, classSection));
    }

}